<?php

class MenuManager extends CComponent
{
	protected $menus = array();
	
	public function init()
	{
		$this->set('main', array(
			array(
				'label' => Yii::t('core', 'Home'),
				'url'   => array('/home/index')
			),
			array(
				'label' => Yii::t('core', 'Projects'),
				'url'   => Yii::app()->getModule('project')->urls['default']
			),
			array(
				'label' => Yii::t('core', 'About me'),
				'url'   => array('/site/about')
			),
			array(
				'label' => Yii::t('core', 'Contact'),
				'url'   => array('/site/contact')
			),
			array(
				'label'   => Yii::t('UserModule.core', 'Login'),
				'url'     => Yii::app()->getModule('user')->urls['login'],
				'visible' => Yii::app()->user->isGuest
			),
			array(
				'label'   => Yii::t('AdminModule.core', 'Admin'),
				'url'     => Yii::app()->getModule('admin')->urls['default'],
				'visible' => !Yii::app()->user->isGuest
			),
			array(
				'label'   => Yii::t('UserModule.core', 'Logout ({username})', array('{username}' => (!Yii::app()->user->isGuest ? Yii::app()->user->alias : ''))),
				'url'     => Yii::app()->getModule('user')->urls['logout'],
				'visible' => !Yii::app()->user->isGuest
			),
		));
	}
	
	public function addMultiple($context, $items)
	{
		foreach($items as $item)
		{
			$this->add($context, $item);
		}
	}
	
	public function add($context, $item)
	{
		if(!isset($this->menus[$context]))
		{
			$this->menus[$context] = array();
		}
		
		return $this->menus[$context][] = $item;
	}
	
	public function set($context, $items)
	{
		$this->menus[$context] = $items;
	}
	
	public function get($context)
	{
		if(!isset($this->menus[$context]))
		{
			return array();
		}
		
		return $this->menus[$context];
	}
}
